import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:znmm/config/app_color.dart';
import 'package:znmm/config/app_gaps.dart';

///输入框
class InputItem extends StatelessWidget {
  final String title;
  final String hintText;
  final TextEditingController controller;
  final TextInputType? keyboardType;
  final bool readOnly;
  final bool showArrow;
  final VoidCallback? onTap;
  final int maxLine;
  final Function(String)? onTextCallback; // 回调参数

  const InputItem({
    Key? key,
    required this.title,
    required this.hintText,
    required this.controller,
    this.keyboardType,
    // ignore: unused_element
    this.readOnly = false,
    this.showArrow = true,
    this.onTap,
    this.maxLine = 1,
    this.onTextCallback,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          title,
          style: TextStyle(
            color: AppColor.black,
            fontSize: 16.sp,
          ),
        ),
        AppGaps.vGaps5w,
        TextField(
          controller: controller,
          style: TextStyle(
            fontSize: 16.sp,
            color: AppColor.black,
          ),
          readOnly: readOnly,
          keyboardType: keyboardType,
          onTap: onTap,
          maxLines: maxLine,
          onChanged: (value) {
            if (onTextCallback != null) {
              onTextCallback!(value);
            }
          },
          decoration: InputDecoration(
            hintText: hintText,
            filled: true,
            fillColor: AppColor.greyF3F4F8,
            isDense: true,
            contentPadding: EdgeInsets.only(
                left: 10.w,
                top: 10.w,
                bottom: 10.w,
                right: readOnly ? 0 : 10.w),
            border: OutlineInputBorder(
              borderRadius: BorderRadius.circular(10.w),
              borderSide: BorderSide.none,
            ),
            suffixIconConstraints: BoxConstraints(
              maxHeight: 25.w,
            ),
            suffixIcon: showArrow
                ? Padding(
                    padding: EdgeInsets.symmetric(horizontal: 10.w),
                    child: Icon(
                      Icons.keyboard_arrow_down_rounded,
                      size: 25.w,
                      color: AppColor.black,
                    ),
                  )
                : null,
          ),
        ),
        AppGaps.vGaps10w,
      ],
    );
  }
}
